package com.tokenplus.thai.components.keyboard

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import androidx.fragment.app.FragmentManager
import com.tokenplus.thai.R
import com.tokenplus.thai.base.BaseFormAction
import com.tokenplus.thai.databinding.ViewNumberKeyboardBinding

class NumberKeyboard : RelativeLayout, BaseFormAction {

    lateinit var mViewBinding: ViewNumberKeyboardBinding
    private lateinit var vRootView: View

    private var mSupportFragmentManager: FragmentManager? = null

    private var mOnActionClickListener: (Int) -> Unit = {}

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(
        context,
        attrs,
        defStyleAttr,
        0
    )

    @SuppressLint("Recycle")
    constructor(
        context: Context?,
        attrs: AttributeSet?,
        defStyleAttr: Int,
        defStyleRes: Int,
    ) : super(
        context,
        attrs,
        defStyleAttr,
        defStyleRes
    ) {
        context?.let {
            vRootView = View.inflate(it, R.layout.view_number_keyboard, this)
            mViewBinding = ViewNumberKeyboardBinding.bind(vRootView)
            initSubviews()
        }
    }

    override fun initSubviews() {
        try {
            mViewBinding.textKeyboardNum0.setOnClickListener {
                mOnActionClickListener.invoke(0)
            }

            mViewBinding.textKeyboardNum1.setOnClickListener {
                mOnActionClickListener.invoke(1)
            }

            mViewBinding.textKeyboardNum2.setOnClickListener {
                mOnActionClickListener.invoke(2)
            }

            mViewBinding.textKeyboardNum3.setOnClickListener {
                mOnActionClickListener.invoke(3)
            }

            mViewBinding.textKeyboardNum4.setOnClickListener {
                mOnActionClickListener.invoke(4)
            }

            mViewBinding.textKeyboardNum5.setOnClickListener {
                mOnActionClickListener.invoke(5)
            }

            mViewBinding.textKeyboardNum6.setOnClickListener {
                mOnActionClickListener.invoke(6)
            }

            mViewBinding.textKeyboardNum7.setOnClickListener {
                mOnActionClickListener.invoke(7)
            }

            mViewBinding.textKeyboardNum8.setOnClickListener {
                mOnActionClickListener.invoke(8)
            }

            mViewBinding.textKeyboardNum9.setOnClickListener {
                mOnActionClickListener.invoke(9)
            }

            mViewBinding.imageKeyboardDel.setOnClickListener {
                mOnActionClickListener.invoke(-1)
            }

            mViewBinding.imageKeyboardDismiss.setOnClickListener {
                mOnActionClickListener.invoke(-2)
            }
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
    }

    override fun setFragmentManager(manager: FragmentManager) {
        mSupportFragmentManager = manager
    }

    override fun setOnActionClickListener(listener: (Int) -> Unit) {
        mOnActionClickListener = listener
    }

    override fun setTitle(title: String) {

    }

    override fun setDetail(detail: String) {

    }

    override fun setContent(content: String) {

    }

    override fun setHint(hint: String) {

    }

    override fun setDetailColor(detailColor: Int) {

    }

    override fun setTitleColor(titleColor: Int) {

    }
}